using System;
using System.Collections;
using Castle.MonoRail.TestSupport;
using NHibernate;
using NUnit.Framework;
using Rhino.Mocks;
using DecisionesInteligentes.iEvalua.Web.Controllers;
using DecisionesInteligentes.iEvalua.Models;
using DecisionesInteligentes.iEvalua.Tests.Helpers;

namespace DecisionesInteligentes.iEvalua.Tests.Controllers
{
	[TestFixture]
	public class ApplicationControllerTestCase : ControllerARMockTestCase<ApplicationController, Application>
	{ 
		public override void SetUp()
		{
			base.SetUp();
			controller = new ApplicationController();
		}
		
		[Test]
		public void Navigate_To_Index()
		{
			IList mockedList = new ArrayList
			{
				new Application { Id = 1, Name = "1" },
				new Application { Id = 2, Name = "2" }
			};
			
			ICriteria criteria = mocks.CreateMock<ICriteria>();
			
			using(mocks.Unordered())
			{
				Expect.Call(session.CreateCriteria(typeof(Application))).Return(criteria);
				Expect.Call(criteria.List()).Return(mockedList);
			}
			
			mocks.ReplayAll();
			
			using(new MockScope(session))
			{
				PrepareController(controller, "", "Application", "Index");
			
				controller.Index();
				
				Assert.IsNotNull(controller.PropertyBag["entities"]);
				Assert.AreEqual(((IList)controller.PropertyBag["entities"]).Count, 2);
			}
		}
	}
}